package thread;
import static java.lang.Thread.sleep;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-05-21
 * Time: 10:44
 */
class MyThread extends Thread {
    //run相当于线程的入口，知道开启线程必须执行run方法
    @Override
    public void run() {
        while (true) {
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("hello thread");
        }
    }
}
public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new MyThread();
        //在系统中创建线程
        thread.start();

        //主线程
        while (true) {
            Thread.sleep(1000);
            System.out.println("hello main");
        }
    }
}
